package com.battle.service.controller.web;

import com.battle.pojo.param.login.AccountLoginParam;
import com.battle.pojo.vo.login.TokenVo;
import com.battle.service.service.in.LoginService;
import nirvana.core.domains.vo.ApiResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 *  web/登录
 * 【描 述】：
 * 【环 境】：J2SE 17
 * 【详 细】：
 *
 * @author 李松林
 * @version v1.0 2024/5/5 新建
 * @since 2024/5/5
 */
@RestController()
@RequestMapping(value = "/login/web")
public class LoginWebController {


    private final LoginService service;

    public LoginWebController(LoginService service) {
        this.service = service;
    }


    /**
     *  测试用 用户id获取token
     *
     * @return
     */
    @GetMapping("/testIdLogin")
    public ApiResult<TokenVo> testIdLogin(@RequestParam Long id) {
       return ApiResult.ok( service.testIdLogin (id));
    }

    /**
     * 获取验证码
     *
     * @return
     */
    @GetMapping("/getAuthCode")
    public void getAuthCode() {
        service.getAuthCode ();
    }



    /**
     *  账号登录
     * @return
     */
    @PostMapping("/accountLogin")
    public ApiResult<TokenVo> accountLogin(@RequestBody @Valid AccountLoginParam param){
        TokenVo vo = service.accountLogin(param);
        return ApiResult.ok(vo);
    }

    /**
     * 刷新token
     *
     * @return
     */
    @GetMapping("/refresh")
    public ApiResult<TokenVo> refresh(){
        TokenVo refresh = service.refresh();
        return ApiResult.ok(refresh);
    }
}
